package com.own.component.netty.util;

import com.own.component.netty.handler.ChannelMap;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;

/**
 * NettyUtil
 *
 * @author chenxueli
 * @date 2021/4/13 15:21
 */
public final class NettyUtil {

    public static void send(Channel channel, String message) {
        if (channel == null || !channel.isOpen()) {
            return;
        }
        channel.writeAndFlush(new TextWebSocketFrame(message));
    }

    public static void send(String channelId, String message) {
        var channel = ChannelMap.MAP.get(channelId);
        send(channel, message);
    }

}
